package com.example.demo.controller;
import com.coze.openapi.service.service.bots.BotService;
import com.example.demo.dto.BotChatRequest;
import com.example.demo.service.CozeBotService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * Bot控制器：处理与Coze智能体的交互请求
 */
@RestController
@RequestMapping("/api/bot")
@RequiredArgsConstructor
@Slf4j
public class CozeBotController {

    private final CozeBotService cozeBotService;

    /**
     * 流式获取智能体聊天响应
     * @param request 聊天请求参数（包含botId、userId、用户输入等）
     * @return 流式响应结果
     */
    @PostMapping("/stream-chat")
    public Flux<String> streamChat(@RequestBody BotChatRequest request) {
        log.info("接收Bot流式聊天请求: {}", request);
        return cozeBotService.streamChat(request);
    }
}
